<?php

require_once("evalable.php");

class PairObject extends Evalable {

    var $a = null;
    var $b = null;

    function PairObject($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    function repr() {
        if ($this->b == null) {
            return "(" . $this->a->repr() . ")";
        } else {
            return "(" . $this->a->repr() . " . " . $this->b->repr() . ")";
        }
    }

    function replaca($val) {
        $this->a = $val;
        return $val;
    }

    function replacd($val) {
        if (get_class($val) == "ListObject") {
            return $val->cons($this->a);
        } else {
            $this->b = $val;
            return $val;
        }
    }

    function first() {
        return $this->a;
    }

    function rest() {
        return $this->b;
    }

    function second() {
        return $this->b;
    }

    function nullp() {
        return new LogicObject(0);
    }

}